<?php

function BuildTabsModul($idP,$select=0)
{
    global $dbsql,$language,$html;
    
    $idP        = intval($idP);

    $sql_select = "select iId,cUrlString,cName from tblcategory where iParentId= $idP and iStatus=1
                    and cLanguage='$language' order by iOrder";
    $rs         = $dbsql->query($sql_select);
    $return     = '';
    while($result   = $dbsql->fetch_array($rs))
    {
        if($select  == $idP)
        {
            $select = $result['iId'];
            $sql_select = "select cIntro from tblcategory where iId=$select";
            $rssl       = $dbsql->query_fetch($sql_select);
            $html->setContent('cIntro',$rssl['cIntro']);
        }
        $class      = ($result['iId']==$select) ? 'class="c"': '';
        $link       = '/'.$html->urlRoot.'/'.$result['cUrlString'];
        $return .='<a href="'.$link.'" '.$class.'>'.$result['cName'].'</a>';        
    }
    if(!empty($return))
    {
        $return = '<div id="abouttabs">'.$return.'<div class="clear"></div></div>';
    }
    return $return;
}

function ListContentByCatId($idP)
{
    
}


function ListCategories($idP)
{
     global $dbsql,$language;
    
    
    $idP        = intval($idP);
    $sql_where  = " from tblcategory where cLanguage='$language' and iStatus=1 and iParentId= $idP";
    
    $sql_select = "select count(iId) as count ".$sql_where;
    $result     = $dbsql->query_fetch($sql_select);
    $countall   = $result['count'];
    
    list($lat,$lall)    = Split_Page($countall);
    
    $sql_select = "select iId,iParentId,cName,cUrlString,cImage,cDescription ".$sql_where;
    $sql_select.= " order by iOrder asc limit $lat,$lall";
    $rs         = $dbsql->query($sql_select);
    $rows       = $dbsql->num_rows($rs);
    $return     = '<div class="ajaxpage">';
    $i          = 0;
    
    while($result   = $dbsql->fetch_array($rs))
    {
        $url    = GetLinkCatById($result['iParentId'],$result['cUrlString']);    
        $class  = ($i%2==0)? 'row1': 'row2';     
        $i ++;
             
        $return .='<div class="tour '.$class.'">';
        $return .='<a class="thumb" href="'.$url.'"><img src="'.GetIntroImg($result['cImage'],true).'" width=130></a>';
        $return .='<a class="title" href="'.$url.'">'.$result['cName'].'</a>';
        $return .='<div class="des">'.$result['cDescription'].'</div>';  
        $return .= '<a class="readmore" href="'.$url.'">'.__('detail').'</a>';              
        $return .='<div class="clear">&nbsp;</div></div>';        
    }
    if($rows==0)
    {
        //$return .= '<div class="notfound">'.getLang('Not found result!').'</div>';
    }
    $return     .= "<div class='clear'>&nbsp;</div></div>";
    return $return;
}

function GetLinkCatById($idcat,$url='')
{
    global $dbsql,$language,$html;
    
    $idcat      = intval($idcat);
    $sql_select = "select iParentId,cUrlString from tblcategory where iId=$idcat limit 1";
    $result     = $dbsql->query_fetch($sql_select);
    $link       = '/';
    if($result['iParentId']>0)
    {
        $link  = GetLinkCatById($result['iParentId']);
    }
    $link   .= $result['cUrlString'].'/'.$url;
    return $link;
}